ff9c63
@@ -74,7 +74,12 @@
         SequenceFileOutputFormat.class, HiveSequenceFileOutputFormat.class);
   }
 
-  static String realoutputFormat;
+  private static ThreadLocal<String> tRealOutputFormat = new ThreadLocal<String>() {
+    @Override
+    protected String initialValue() {
+      return null;
+    }
+  };
 
   @SuppressWarnings("unchecked")
   private static Map<Class<? extends OutputFormat>, Class<? extends HiveOutputFormat>>
@@ -105,11 +110,9 @@
public static synchronized void registerOutputFormatSubstitute(
     }
     Class<? extends HiveOutputFormat> result = outputFormatSubstituteMap
         .get(origin);
-    //register this output format into the map for the first time
-    if ((storagehandlerflag == true) && (result == null)) {
+    if ((storagehandlerflag == true) && (result == null || result == HivePassThroughOutputFormat.class)) {
       HiveFileFormatUtils.setRealOutputFormatClassName(origin.getName());
       result = HivePassThroughOutputFormat.class;
-      HiveFileFormatUtils.registerOutputFormatSubstitute((Class<? extends OutputFormat>) origin,HivePassThroughOutputFormat.class);
     }
     return result;
   }
@@ -120,7 +123,7 @@
public static synchronized void registerOutputFormatSubstitute(
   @SuppressWarnings("unchecked")
   public static String getRealOutputFormatClassName()
   {
-    return realoutputFormat;
+    return tRealOutputFormat.get();
   }
 
   /**
@@ -129,7 +132,7 @@
public static String getRealOutputFormatClassName()
   public static void setRealOutputFormatClassName(
       String destination) {
     if (destination != null){
-      realoutputFormat = destination;
+      tRealOutputFormat.set(destination);
     }
     else {
       return;
